/*     */ package com.zimbra.cs.account.ldap.upgrade;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.Entry.EntryType;
/*     */ import com.zimbra.cs.account.ldap.LdapDIT;
/*     */ import com.zimbra.cs.account.ldap.LdapProv;
/*     */ import com.zimbra.cs.ldap.IAttributes;
/*     */ import com.zimbra.cs.ldap.LdapClient;
/*     */ import com.zimbra.cs.ldap.LdapServerType;
/*     */ import com.zimbra.cs.ldap.LdapUsage;
/*     */ import com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor;
/*     */ import com.zimbra.cs.ldap.ZAttributes;
/*     */ import com.zimbra.cs.ldap.ZLdapContext;
/*     */ import com.zimbra.cs.ldap.ZLdapFilter;
/*     */ import com.zimbra.cs.ldap.ZLdapFilterFactory;
/*     */ import com.zimbra.cs.ldap.ZMutableEntry;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class BUG_57875
/*     */   extends UpgradeOp
/*     */ {
/*     */   private static final String ATTR_NAME = "zimbraGalLdapGroupHandlerClass";
/*     */   private static final String OLD_VALUE = "com.zimbra.cs.gal.ADGalGroupHandler";
/*     */   private static final String NEW_VALUE = "com.zimbra.cs.account.grouphandler.ADGroupHandler";
/*     */   
/*     */   void doUpgrade()
/*     */     throws ServiceException
/*     */   {
/*  40 */     ZLdapContext zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UPGRADE);
/*     */     try {
/*  42 */       upgradeGlobalConfig(zlc);
/*  43 */       upgradeDomains(zlc);
/*  44 */       upgradeDataSources(zlc);
/*     */     } finally {
/*  46 */       LdapClient.closeContext(zlc);
/*     */     }
/*     */   }
/*     */   
/*     */   Description getDescription()
/*     */   {
/*  52 */     return new Description(this, new String[] { "zimbraGalLdapGroupHandlerClass" }, new Entry.EntryType[] { Entry.EntryType.GLOBALCONFIG, Entry.EntryType.DOMAIN, Entry.EntryType.DATASOURCE }, "com.zimbra.cs.gal.ADGalGroupHandler", "com.zimbra.cs.account.grouphandler.ADGroupHandler", null);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   private void upgradeGlobalConfig(ZLdapContext zlc)
/*     */     throws ServiceException
/*     */   {
/*  61 */     String[] bases = { this.prov.getDIT().configBranchBaseDN() };
/*     */     
/*  63 */     String query = "(&" + ZLdapFilterFactory.getInstance().globalConfig().toFilterString() + "(" + "zimbraGalLdapGroupHandlerClass" + "=" + "com.zimbra.cs.gal.ADGalGroupHandler" + ")" + ")";
/*     */     
/*     */ 
/*  66 */     upgrade(zlc, bases, query);
/*     */   }
/*     */   
/*     */   private void upgradeDomains(ZLdapContext zlc) {
/*  70 */     String[] bases = this.prov.getDIT().getSearchBases(16);
/*  71 */     String query = "(&" + ZLdapFilterFactory.getInstance().allDomains().toFilterString() + "(" + "zimbraGalLdapGroupHandlerClass" + "=" + "com.zimbra.cs.gal.ADGalGroupHandler" + ")" + ")";
/*     */     
/*     */ 
/*  74 */     upgrade(zlc, bases, query);
/*     */   }
/*     */   
/*     */   private void upgradeDataSources(ZLdapContext zlc) {
/*  78 */     String[] bases = { this.prov.getDIT().mailBranchBaseDN() };
/*     */     
/*  80 */     String query = "(&" + ZLdapFilterFactory.getInstance().allDataSources().toFilterString() + "(" + "zimbraGalLdapGroupHandlerClass" + "=" + "com.zimbra.cs.gal.ADGalGroupHandler" + ")" + ")";
/*     */     
/*     */ 
/*  83 */     upgrade(zlc, bases, query);
/*     */   }
/*     */   
/*     */   private void upgrade(ZLdapContext modZlc, String[] bases, String filter) {
/*  87 */     SearchLdapOptions.SearchLdapVisitor visitor = new Bug57875Visitor(this, modZlc);
/*     */     
/*  89 */     String[] attrs = { "zimbraGalLdapGroupHandlerClass" };
/*     */     
/*  91 */     for (String base : bases) {
/*     */       try {
/*  93 */         this.printer.format("\n=== Searching LDAP: base = %s, filter = %s\n", new Object[] { base, filter });
/*  94 */         this.prov.searchLdapOnMaster(base, filter, attrs, visitor);
/*     */       }
/*     */       catch (ServiceException e) {
/*  97 */         this.printer.println("Caught ServiceException while searching " + filter + " under base " + base);
/*  98 */         this.printer.printStackTrace(e);
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   private static class Bug57875Visitor extends SearchLdapOptions.SearchLdapVisitor {
/*     */     private UpgradeOp upgradeOp;
/*     */     private ZLdapContext modZlc;
/*     */     
/*     */     Bug57875Visitor(UpgradeOp upgradeOp, ZLdapContext modZlc) {
/* 108 */       super();
/* 109 */       this.upgradeOp = upgradeOp;
/* 110 */       this.modZlc = modZlc;
/*     */     }
/*     */     
/*     */     public void visit(String dn, IAttributes ldapAttrs)
/*     */     {
/*     */       try {
/* 116 */         if (this.upgradeOp.verbose) {
/* 117 */           this.upgradeOp.printer.println("Found entry " + dn);
/*     */         }
/*     */         
/* 120 */         doVisit(dn, (ZAttributes)ldapAttrs);
/*     */       } catch (ServiceException e) {
/* 122 */         this.upgradeOp.printer.println("entry skipped, encountered error while processing entry at:" + dn);
/* 123 */         this.upgradeOp.printer.printStackTrace(e);
/*     */       }
/*     */     }
/*     */     
/*     */     public void doVisit(String dn, ZAttributes ldapAttrs) throws ServiceException {
/* 128 */       String curValue = ldapAttrs.getAttrString("zimbraGalLdapGroupHandlerClass");
/* 129 */       if ("com.zimbra.cs.gal.ADGalGroupHandler".equals(curValue)) {
/* 130 */         ZMutableEntry entry = LdapClient.createMutableEntry();
/* 131 */         entry.setAttr("zimbraGalLdapGroupHandlerClass", "com.zimbra.cs.account.grouphandler.ADGroupHandler");
/* 132 */         this.upgradeOp.replaceAttrs(this.modZlc, dn, entry);
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/ldap/upgrade/BUG_57875.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */